package com.example.springdatajpa.dao;

import com.example.springdatajpa.entity.Order;
import org.aspectj.weaver.ast.Or;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * dao 层 继承 JpaRepository 接口
 */
@Repository
public interface OrderDao extends JpaRepository<Order,Long> {
    /**
     * 基于 SpringDataJpa 方法名称规则查询
     * @param str
     * @return
     */
    public List<Order> findByNoteIs(String str);

    /**
     * 基于@Query注解查询
     * JPQL语句和HQL语句大体相同
     * @param name
     * @return
     */
    @Query(value = "from Order where note = ?1 and id=?2")
    List<Order> queryOrderByNoteUseJPQL(String name,Long id);

    /**
     * 使用原生SQL
     * @param note
     * @param id
     * @return
     */
    @Query(value = "select * from Order where note = ?1 and id=?2",nativeQuery = true)
    List<Order>queryOrderByNoteUseSQL(String note,Long id);

    /**
     * JPQL 修改 加入Modify注解
     * @param note
     * @param id
     */
    @Query(value = "update Order set note=?1 where id=?2")
    @Modifying
    void updateUseById(String note,Long id);

}
